home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Graphics Programming (2nd Edition) / Visual Basic Graphics Programming 2nd Edition.iso / OldSrc / CH5 / SRC / ARCTANTR.BAS < prev    next >
Encoding:
BASIC Source File  |  1996-02-28  |  704 b   |  30 lines

  1. Attribute VB_Name = "AtcTan"
  2. Option Explicit
  3.  
  4. Global Const PI = 3.14159
  5. Global Const PI_TIMES_2 = PI * 2
  6. Global Const PI_OVER_2 = PI / 2
  7. Global Const DEG_TO_RAD = PI / 180#
  8.  
  9. ' ************************************************
  10. ' Return the arc tangent of y/x taking into
  11. ' account the proper quadrant.
  12. ' ************************************************
  13. Function Arctan2(x As Single, y As Single)
  14. Dim theta As Single
  15.  
  16.     If x = 0 Then
  17.         If y > 0 Then
  18.             Arctan2 = PI_OVER_2
  19.         Else
  20.             Arctan2 = -PI_OVER_2
  21.         End If
  22.     Else
  23.         theta = Atn(y / x)
  24.         If x < 0 Then theta = PI + theta
  25.         Arctan2 = theta
  26.     End If
  27. End Function
  28.  
  29.  
  30.